/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2024-01-07 20:43:05
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-02-03 18:19:27
 * @FilePath: \My-bolg\My_Blog\src\directives\imageLoading.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export default {
    beforeMount(el, binding) {
        if (!binding.value) return;
        var img = new Image();
        img.src = binding.value;
        // 创建一个loading的img标签
        let cup = document.createElement("div");
        cup.classList.add("coffee_cup");
        el.appendChild(cup); // 插入dom
    
        img.onload = () => {
          el.removeChild(cup); // 加载成功移除loading
        };
    
        img.onerror = () => {
          el.removeChild(cup); // 加载失败移除loading 展示el自定义的错误
        };
      },
}